#include<bits/stdc++.h>
using namespace std;
int t,mod,f[200010][500],n,ans;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	cin>>t>>mod;
	for(int i=0;i<=450;i++)f[0][i]=1;
	for(int i=1;i<=2e5;i++){
		for(int j=1;j<=min(i,450);j++)f[i][j]=(f[i][j-1]+f[i-j][j])%mod;
		for(int j=min(i,450)+1;j<=450;j++)f[i][j]=f[i][j-1];
	}
	while(t--){
		cin>>n,ans=0;
		for(int i=1;i*i<=n;i++)if((n-i*i)%2==0)ans=(ans+f[(n-i*i)/2][i]%mod)%mod;
		cout<<ans<<"\n";
	}
	return 0;
}
